package com.winhxd.b2c.common.feign.order;

import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.constant.ServiceName;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.order.condition.OrderPayCallBackCondition;
import com.winhxd.b2c.common.domain.order.condition.OrderRefundCallbackCondition;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: hxd-outlet-parent
 * @description: 订单支付、退款  回调Client
 * @author: liuhanning
 * @create: 2019-01-08 19:49
 **/
@FeignClient(value = ServiceName.ORDER_SERVICE, fallbackFactory = OrderCallBackFallback.class)
public interface OrderCallBackClient {
    /**
    * @Description: 支付回调业务处理
    * @Author: liuhanning
    * @Date:  2019-01-08 20:33
    */
    @RequestMapping(value = "/orderPay/4066/v1/callbackOrderPay", method = RequestMethod.POST)
    ResponseResult<Boolean> callbackOrderPay(@RequestBody OrderPayCallBackCondition condition);
    /**
    * @Description:  退款回调业务处理
     * @Author: liuhanning
    * @Date:  2019-01-08 20:33
    */
    @RequestMapping(value = "/orderPay/4067/v1/callbackOrderRefund", method = RequestMethod.POST)
    ResponseResult<Boolean> callbackOrderRefund(@RequestBody  OrderRefundCallbackCondition condition);

}
@Component
class OrderCallBackFallback implements OrderCallBackClient, FallbackFactory<OrderCallBackClient> {
    private Throwable throwable;
    private static final Logger logger = LoggerFactory.getLogger(OrderDataStatisticsServiceFallback.class);

    public OrderCallBackFallback() {
    }

    public OrderCallBackFallback(Throwable throwable) {
        this.throwable = throwable;
    }

    @Override
    public OrderCallBackClient create(Throwable throwable) {
        return new OrderCallBackFallback(throwable);
    }

    @Override
    public ResponseResult<Boolean> callbackOrderPay(OrderPayCallBackCondition condition) {
        logger.error("订单支付回调失败  OrderCallBackClient -> callbackOrderPay", throwable);
        return new ResponseResult<>(BusinessCode.CODE_1001);
    }

    @Override
    public ResponseResult<Boolean> callbackOrderRefund(OrderRefundCallbackCondition condition) {
        logger.error("订单退款回调失败  OrderCallBackClient -> callbackOrderRefund", throwable);
        return new ResponseResult<>(BusinessCode.CODE_1001);
    }
}